<template>
    <div id="myChart" :style="{width: '1400px', height: '600px'}">
    </div>
</template>
<script>

    import axios from 'axios'
    export default {
        name: 'Echarts',
        mounted(){
            let _this=this

            axios.get('http://localhost:8888/guoBeforeTen').then(function (response) {
                // 基于准备好的dom，初始化echarts实例
                let myChart = _this.$echarts.init(document.getElementById('myChart'))
                // 绘制图表
                myChart.setOption({
                    title: {
                        text: '国产动画前十展示',
                        subtext: '单位：万'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {            // Use axis to trigger tooltip
                            type: 'shadow'        // 'shadow' as default; can also be 'line' or 'shadow'
                        }
                    },
                    legend: {
                        data: ['播放数', '追番数', '评论数']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value'
                    },
                    yAxis: {
                        type: 'category',
                        data: response.data.name
                    },
                    series: [
                        {
                            name: '播放数',
                            type: 'bar',
                            stack: 'total',
                            label: {
                                show: true
                            },
                            emphasis: {
                                focus: 'series'
                            },
                            data: response.data.views
                        },
                        {
                            name: '追番数',
                            type: 'bar',
                            stack: 'total',
                            label: {
                                show: true
                            },
                            emphasis: {
                                focus: 'series'
                            },
                            data: response.data.fan
                        },
                        {
                            name: '评论数',
                            type: 'bar',
                            stack: 'total',
                            label: {
                                show: true
                            },
                            emphasis: {
                                focus: 'series'
                            },
                            data: response.data.comment
                        }
                    ]
                });
            })

        }
    }
</script>